/*
 * @Description  :
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2022-03-30 14:26:01
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-04-09 14:10:37
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\tax-management\\components\\order-reporting\\verify-result\\verify-result.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STColumn, STComponent, STRequestOptions } from '@delon/abc/st';
import { SFSchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { TaxManagementService } from '../../../services/tax-management.service';

@Component({
  selector: 'app-tax-management-order-reporting-verify-result',
  templateUrl: './verify-result.component.html',
})
export class TaxManagementOrderVerifyResultComponent implements OnInit {
  searchSchema: SFSchema = {
    properties: {
      no: {
        type: 'string',
        title: '编号'
      }
    }
  };
  @ViewChild('st') private readonly st!: STComponent;
  columns: STColumn[] = [];
  record: any = {}
  subjectType: string = '0';
  tabs: any[] = [
    { name: '平台信息', value: '0' },
    { name: '货主信息', value: '1' },
    { name: '司机信息', value: '2' },
    { name: '订单信息', value: '3' },
  ];

  // get reqParams() {
  //   console.log(this.subjectType);
  //   const params ={
  //     subjectId: this.record?.shipperId,
  //     subjectType: this.subjectType,
  //   }
  //   return params;
  // }
  beforeReq = (requestOptions: STRequestOptions) => {
    let a: string = '';
    switch (this.subjectType) {
      case '0':
        a = this.record?.networkTransporterId;
        break
      case '1':
        a = this.record?.shipperId;
        break
      case '2':
        a = this.record?.driverId;
        break
      case '3':
        a = this.record?.wayBillId;
        break
    }
    Object.assign(requestOptions.body, {
      subjectId: a,
      subjectType: this.subjectType,
    });
    return requestOptions;
  };
  afterRes = (data: any[], rawData?: any) => {
    console.log(data)
    return data.map(item => ({
      ...item,
    }));
  };
  constructor(public service: TaxManagementService, private modalRef: NzModalRef, public router: Router) {
  }

  ngOnInit(): void {
    console.log(this.record);

    this.initST();
  }

  /**
 * 初始化数据列表
 */
  initST() {
    this.columns = [
      { title: '序号', type: 'no', className: 'text-center', width: '60px', },
      { title: '校验字段', index: 'checkFieldName', className: 'text-center', width: '120px', },
      {
        title: '是否必填',
        index: 'requiredStatus',
        className: 'text-center',
        width: '100px',
        type: 'enum',
        enum: {
          0: '否',
          1: '是'
        }
      },
      { title: '上传值', render: 'fieldValue', className: 'text-center', width: '150px', },
      {
        title: '本地校验', index: 'checkStatus', className: 'text-center', width: '100px',
        type: 'enum',
        enum: {
          0: '校验中',
          1: '通过',
          2: '不通过'
        }
      },
      { title: '错误内容', index: 'remark', className: 'text-center', width: '150px', },
    ]
  }


  add(): void {
    // this.modal
    //   .createStatic(FormEditComponent, { i: { id: 0 } })
    //   .subscribe(() => this.st.reload());
  }

  selectTab(e: any) {
    setTimeout(() => {
      console.log(e?.value);

      this.subjectType = e?.value;
      console.log(this.subjectType);
      this.st.load(1);
    })
  }

  update() {
    if (this.record?.billType === '1') {
      window.open(location.origin + `/#/order-management/vehicle-detailChange/${this.record?.id}`)

    } else if (this.record.billType === '2') {
      window.open(location.origin + `/#/order-management/bulk-detailChange/${this.record?.id}`);
    }
  }
  close(): void {
    this.modalRef.destroy();
  }


}
